﻿<UserControl x:Class="WeatherFrame.WeatherItemView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:my="clr-namespace:WeatherFrame"             
    mc:Ignorable="d"  Name="WivRoot"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="480" d:DesignWidth="800"
             Height="480" Width="800">
    <UserControl.Resources>
        <my:VisConverter x:Key="VisConverter"/>
    </UserControl.Resources>

    <Grid>
        <Border HorizontalAlignment="Center" VerticalAlignment="Top" Margin="20"  Opacity="0.5"
                 Visibility="{Binding IsErrorState,Converter={StaticResource VisConverter}}">
            <my:WeatherIcon DataContext="GreyCloudRain" Width="180" Height="180" />
        </Border>
        <Border HorizontalAlignment="Center" VerticalAlignment="Top" Margin="20"  Opacity="0.5"
                 Visibility="{Binding IsWaitingForWeather,Converter={StaticResource VisConverter}}">
            <my:SunIcon Width="200" Height="200"  Loaded="Image_ImageOpened_1">
                <my:SunIcon.RenderTransform>
                <RotateTransform CenterX="100" CenterY="100"/>
                </my:SunIcon.RenderTransform>
            </my:SunIcon>
        </Border>
        <Image my:LowProfileImageLoader.UriSource="{Binding ImageUri}" Stretch="Fill" Name="WeatherImage" Tag="{Binding ElementName=WivRoot}"
               ImageOpened="Image_ImageOpened" Opacity="0" ImageFailed="Image_ImageFailed"
               MouseLeftButtonUp="WeatherImage_MouseLeftButtonDown"/>
        <Image Stretch="Fill" Name="WeatherImageMedium" MouseLeftButtonUp="WeatherImage_MouseLeftButtonDown"/>               
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <StackPanel Orientation="Vertical" VerticalAlignment="Top" IsHitTestVisible="False">
                <my:HighVisTextBlock Opacity="0.45" Tag="{Binding LocationText}"
                               FontSize="20" Margin="5,-4,5,0"/>

                <my:HighVisTextBlock Opacity="0.8" Margin="20,-25" Tag="{Binding TimePeriod}"
                               FontSize="60"/>
                <!--<my:PageIndicator Margin="24,-12,20,0"/>-->
            </StackPanel>
            <ScrollViewer Name="ConditionScroller" Grid.Row="1" VerticalScrollBarVisibility="Disabled" >
                <Grid Name="ConditionGrid" Margin="0,0,0,-100">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="100"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="758"/>
                        <ColumnDefinition Width="776"/>
                    </Grid.ColumnDefinitions>
                    <Border Grid.ColumnSpan="2" MouseLeftButtonUp="WeatherImage_MouseLeftButtonDown" Background="Transparent"/>

                    <Grid VerticalAlignment="Bottom"  Opacity="0.6" Margin="10,0,10,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <!--<Image Source="{Binding IconPath}" Width="100" VerticalAlignment="Bottom"/>-->
                        <my:CachedHighVisWeatherIcon Width="96" Height="96" Margin="2" VerticalAlignment="Bottom" DataContext="{Binding IconPath}" Background="#01000000"
                                               MouseLeftButtonDown="HighVisWeatherIcon_MouseLeftButtonDown"/>
                    <!--<my:HighVisTextBlock FontSize="48" Tag="{Binding TempText}" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"
                                       />-->
                        <StackPanel Name="TempPanel" Orientation="Horizontal" VerticalAlignment="Bottom" Grid.Column="1" Margin="5,0" MouseLeftButtonDown="HighVisWeatherIcon_MouseLeftButtonDown"
                                    >
                            <Border Name="TempLeft" VerticalAlignment="Center" Width="20" Height="10" Margin="-5,0"
                                    Visibility="Collapsed"/>
                            <StackPanel Orientation="Vertical">
                                <StackPanel Orientation="Horizontal">
                                    <Border CornerRadius="20,20,0,0" Background="White" Name="MinTempElement">
                                        <TextBlock FontSize="40"  Foreground="#99000000" FontWeight="Bold" Margin="7,-6,5,-7"/>
                                    </Border>
                                    <Border Name="TempConnector" Background="White" VerticalAlignment="Bottom" Width="20" Height="1" Margin="-5,0"
                                    Visibility="Collapsed"/>
                                    <Border CornerRadius="20,20,0,0" Background="White" Name="MaxTempElement">
                                        <TextBlock FontSize="40"  Foreground="#99000000" FontWeight="Bold" Margin="7,-6,5,-7"/>
                                    </Border>
                                </StackPanel>
                                <Border Name="TempUnit"  Background="White" HorizontalAlignment="Stretch" Visibility="Collapsed">
                                    <TextBlock Name="TempUnitText" FontWeight="Bold" Foreground="#99000000" TextAlignment="Center"  FontSize="14" Margin="0,-4,0,-2"/>
                                </Border>
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                    <Grid Name="ImageInfo" MouseLeftButtonDown="TextBlock_MouseLeftButtonDown" Grid.Column="1" Margin="0,5" Opacity="0"
                          >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="2*"/>                            
                            <ColumnDefinition Width="3*"/>
                        </Grid.ColumnDefinitions>
                        <my:HighVisTextBlock FontSize="40" Tag="©" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,0,-5"/>
                        <my:HighVisTextBlock Grid.Column="1" FontSize="32"  Tag="{Binding ImageCredit}" VerticalAlignment="Bottom"/>
                        <my:HighVisTextBlock FontStyle="Italic" Grid.Column="2" 
                                             FontSize="32"  Tag="{Binding ImageTitle}" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
                    </Grid>
                    <Border CornerRadius="0,0,0,0" Grid.Row="1" Grid.ColumnSpan="2" Background="#99FFFFFF" Width="800" Padding="10"
                            HorizontalAlignment="Left">
                    <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                                <TextBlock Foreground="#000000" FontSize="28" Text="{Binding WeatherCondition.Description}"/>
                            <StackPanel Grid.Row="1" Orientation="Horizontal">
                                <TextBlock Foreground="#AA000000" FontSize="24" Text="wind " VerticalAlignment="Center"/>
                                <TextBlock Foreground="#000000" FontSize="28" Text="{Binding WindspeedMph}"/>
                                <TextBlock Foreground="#000000" FontSize="24" Text="mph "  VerticalAlignment="Center"/>
                                <TextBlock Foreground="#000000" FontSize="28" Text="{Binding WindDirection}"/>
                                <TextBlock Foreground="#AA000000" FontSize="24" Text="precipitation "  VerticalAlignment="Center" Margin="30,0,0,0"/>
                                <TextBlock Foreground="#000000" FontSize="28" Text="{Binding PrecipitationMm}"/>
                                <TextBlock Foreground="#000000" FontSize="24" Text="mm"  VerticalAlignment="Center"/>
                            </StackPanel>
                            <Border Padding="15,5" Grid.Column="1" Grid.RowSpan="2" Background="#01000000" MouseLeftButtonDown="WeatherImage_MouseLeftButtonDown">
                                <Path Opacity="0.3" Fill="Black"
                                  Data="M0,0 H50 L25,40 L0,0 M0,50 H50 L25,90 L0,50" Stretch="Uniform" Width="30" Height="70"/>
                            </Border>
                        </Grid>
                    </Border>
                </Grid>
            </ScrollViewer>
        </Grid>
        <Border Visibility="{Binding IsErrorState,Converter={StaticResource VisConverter}}"  VerticalAlignment="Top" Margin="0,290,0,0">
            <StackPanel Orientation="Vertical">
                <TextBlock Text="{Binding ErrorText}" HorizontalAlignment="Center" Foreground="DarkGray" FontSize="36" Margin="0,0,0,5"
                           TextAlignment="Center"/>
                <Button HorizontalAlignment="Center" BorderBrush="DarkGray" Foreground="DarkGray" Click="Retry_Click">
                    <Button.Template>                        
                        <ControlTemplate TargetType="Button">
                            <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" 
                                        Background="{TemplateBinding Background}"
                                        Margin="{StaticResource PhoneTouchTargetOverhang}"
                    >
                                <ContentControl x:Name="ContentContainer" Content="{TemplateBinding Content}"/>
                            </Border>
                        </ControlTemplate>
                    </Button.Template>
                    <TextBlock FontSize="24" Margin="5,0,5,5">try again</TextBlock>
                </Button>
            </StackPanel>
        </Border>

    </Grid>
</UserControl>
